package org.arch_learn.rpc.consumer.controller;

import org.arch_learn.rpc.consumer.service.UserService;
import org.arch_learn.rpc.nz_rpc_api.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping(value = "/info/{id}")
    public ResponseEntity<Object> userInfo(@PathVariable Integer id) {
        User user = userService.selectUserById(id);
        return ResponseEntity.ok(user);
    }

    @PostMapping(value = "/add")
    public ResponseEntity<String> addUser(@RequestBody User user) {
        userService.addUser(user);
        return ResponseEntity.ok("用户添加成功！");
    }
}
